<?php
class ymdian_dakuanControl extends skymvc{
	
	public function __construct(){
		parent::__construct();
	}
	
	public function onDefault(){
		$where=" shopid=".SHOPID;
		$status=get('status','i');
		 
		$url.="&status=$status";
		$start=get('per_page','i');
		$limit=50;
		$option=array(
			"where"=>$where,
			"order"=>"id DESC",
			"start"=>$start,
			"limit"=>$limit
		);
		$rscount=true;
		$data=M("ymdian_dakuan")->select($option,$rscount);
		$pagelist=$this->pagelist($rscount,$limit,$url); 
		$this->smarty->assign(array(
			"data"=>$data,
			"pagelist"=>$pagelist
		));
		$this->smarty->display("ymdian_dakuan/index.html");	
	}
	
	public function onAdd(){
		$id=get('id','i');
		$data=M("ymdian_dakuan")->selectRow("id=".$id);
		
		$this->smarty->assign(array(
			"data"=>$data
		));
		
		$this->smarty->display("ymdian_dakuan/add.html");
	}
	
	public function onSave(){
		$id=get_post('id','i');
		$row=M("ymdian_dakuan")->selectRow("id=".$id);
		if($row['shopid']!=SHOPID){
			$this->goAll("暂无权限",1);
		}
		if($row['status']==2){
			$this->goAll("暂不能修改");
		}
		$ispay=post('ispay','i');
		$ispay=Max($ispay,$row['ispay']);
		$payinfo=post('payinfo','h');
		$data=array(
				"ispay"=>$ispay,
				"payinfo"=>$payinfo
			);
		if($ispay==2){
			if(empty($payinfo)){
				$this->goAll("请填写支付信息",1);
			}
			if($row['ispay']!=2){
				$data['paytime']=time();
				if($data['paytime']>$row['endtime']){
					$data['iswg']=1;
				}
			}
		}
		M("ymdian_dakuan")->update($data,"id=".$id);
		$this->goALl("保存成功");
	}
	
}
?>